<?php
/**
 * Z-Blog with PHP.
 *
 * @author  Z-BlogPHP Team
 * @version 2.0 2013-07-05
 */
require '../function/c_system_base.php';
require '../function/c_system_admin.php';
$zbp->Load();

$action = 'DatasourcePst';
if (!$zbp->CheckRights($action)) {
    $zbp->ShowError(6, __FILE__, __LINE__);
    die();
}
$blogtitle = $lang['msg']['datasource_edit'];

$id = null;
if (isset($_GET['id'])) {
    $id = (int) GetVars('id', 'GET');
    $action = 'DatasourceEdt';
    if (!$zbp->CheckRights($action)) {
        $zbp->ShowError(6, __FILE__, __LINE__);
        die();
    }
} else {
    $id = 0;
    $action = 'DatasourceNew';
    if (!$zbp->CheckRights($action)) {
        $zbp->ShowError(6, __FILE__, __LINE__);
        die();
    }
}
$info = $zbp->GetDatasourceByID($id);
require ZBP_PATH . 'zb_system/admin/admin_header.php';
require ZBP_PATH . 'zb_system/admin/admin_top.php';
?>
<div id="divMain">
    <div class="divHeader2">
        <?php echo $lang['msg']['datasource_edit']; ?></div>
    <div class="SubMenu">
        <?php
        HookFilterPlugin('Filter_Plugin_Datasource_Edit_SubMenu');
        ?>
    </div>
    <div id="divMain2"  class="edit datasource_edit">
        <form id="edit" name="edit" method="post" action="#">
            <input id="edtId" name="ID" type="hidden" value="<?php echo $info->ID; ?>" />
            <p>
                <span class='title'>
                    <?php echo $lang['msg']['py_end']; ?>:</span>
                <br />
                <input id="end_0" class="radio" <?php if ($info->End == '0') {echo 'checked';}?> size="40" name="End" type="radio" value="0" />
                <label for="end_0">否</label>&emsp;
                <input id="end_1" class="radio" <?php if ($info->End == '1') {echo 'checked';}?> size="40" name="End" type="radio" value="1" />
                <label for="end_1">是</label>
            </p>
            <p>
                <span class='title'>
                    <?php echo $lang['msg']['db_user']; ?>:</span>
                <br />
                <input id="edtDbUser" class="edit" size="40" name="Db_user" type="text" value="<?php echo $info->Db_user; ?>" autocomplete="off" />
            </p>

            <p>
                <span class='title'>
                    <?php echo $lang['msg']['db_password']; ?>:</span>
                <br />
                <input id="edtDbPassword" class="edit" size="40" name="Db_password" type="password" value="<?php echo "******"; ?>" autocomplete="off" />
            </p>

            <p>
                <span class='title'>
                    <?php echo $lang['msg']['db_name']; ?>:</span>
                <br />
                <input id="edtDbName" class="edit" size="40" name="Db_name" type="text" value="<?php echo $info->Db_name; ?>" autocomplete="off" />
            </p>

            <p>
                <span class='title'>
                    <?php echo $lang['msg']['db_host']; ?>:</span>
                <br />
                <input id="edtDbHost" class="edit" size="40" name="Db_host" type="text" value="<?php if ($info->Db_host) echo $info->Db_host; else echo 'localhost'; ?>" autocomplete="off" />
            </p>
            <p>
                <span class='title'>
                    <?php echo $lang['msg']['db_port']; ?>:</span>
                <br />
                <input id="edtDbPort" class="edit" size="40" name="Db_port" type="text" value="<?php if($info->Db_port) echo $info->Db_port; else echo '3306';?>" autocomplete="off" />
            </p>
            <p>
                <span class='title'>
                    <?php echo $lang['msg']['web_aliases']; ?>:</span>
                <br />
                <input id="edtWebAliases" class="edit" size="40" name="Web_aliases" type="text" value="<?php echo $info->Web_aliases; ?>" autocomplete="off" />
            </p>
            <p>
                <span class='title'>
                    <?php echo $lang['msg']['ex_description']; ?>:</span>
                <br />
                <div id="carea" style="margin:5px 0 0 0" class="editmod editmod3">
                    <textarea id="edtExDescription" rows="10%" cols="100%" name="Ex_description" style="padding: 10px"><?php echo FormatString($info->Ex_description, '[html-format]');?></textarea>
                </div>
            </p>
            <p>
                <input type="submit" class="button" value="保存" id="btnPost" onclick="return checkInfo();" />
            </p>
        </form>
        <script>
            function checkInfo() {
                document.getElementById("edit").action = "<?php echo BuildSafeCmdURL('act=DatasourcePst'); ?>";
                if (!$("#edtDbUser").val()) {
                    alert("<?php echo $lang['error']['72']; ?>");
                    return false
                }
            }

        </script>
        <script>
            ActiveLeftMenu("aDataSource");
        </script>
        <script>
            AddHeaderIcon("<?php echo $zbp->host . 'zb_system/image/common/new_32.png'; ?>");
        </script>
        <script>
            AddHeaderFontIcon("icon-layers-fill");
        </script>
    </div>
</div>
<?php
require ZBP_PATH . 'zb_system/admin/admin_footer.php';

RunTime();